package com.youbus.supplierCenter.supplier.action;

import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.infoservice.framework.ActionImpl;
import com.infoservice.framework.datacontext.ActionContext;
import com.infoservice.po.PageQuery;
import com.youbus.customer.exception.OrderException;
import com.youbus.framework.comm.YBCommonContant;
import com.youbus.framework.comm.YoubusNativeCacheService;
import com.youbus.framework.util.POFactoryUtil;
import com.youbus.marketApplication.rentBus.entity.MarketTraceArgBean;
import com.youbus.marketApplication.rentBus.factory.RentServiceFactory;
import com.youbus.marketApplication.rentBus.service.PersonaService;
import com.youbus.marketApplication.util.CopyUtil;

/**
 * ${actionDesc}Action
 *
 * @author AndyTain
 *
 */
public class ${actionName_Iii} extends ActionImpl {
	private static Logger LOGGER = LogManager.getLogger(${actionName_Iii}.class);

	@Override
	protected int performExecute(ActionContext act) {

		try {
			// 获取参数
            ${paramClass_Iii} argBean = new ${paramClass_Iii}();
<#--入参循环遍历 -->
<#list paramList as temp>
			argBean.set${temp.t0_Iii}(act.getStringValue("${temp.t0_iii}"));
</#list>
			argBean.setSupCode(act.getStringValue(YBCommonContant.SESSION_SUP_CUST_CODE));
<#if optType=="4">
			argBean.setOptMemberId(StringUtil.getInt(act.getStringValue(YBCommonContant.SESSION_EMP_ID)));
			argBean.setOptMemberName(act.getStringValue(YBCommonContant.SESSION_USER_NAME));
</#if>

			//获取service
			SupplyService service = SupplierServiceFactory.getSupplyService();

<#-- 操作类型区分处理 1 grid ，2 list ，3 opt -->
<#if optType == "1">
			// 获取查询结果
			PageQuery pageQuery = service.${methodName}(act.getConnection(),POFactoryUtil.getPageSize(act),argBean);
			List pageList = pageQuery.getResult("PAGE", POFactoryUtil.getCurrentPageNo(act));
			POFactoryUtil.genJsonResultStr(act, pageList, pageQuery.getTotalRecords());

<#elseif optType == "2">
			// 获取查询结果 单个 TODO
			${dtoClass_Iii} result = service.${methodName_iii}(act.getConnection(), argBean);
			act.setStringValue("jsonResult", CopyUtil.converJsonString(result));

			// 获取查询结果 列表 TODO
			List<${dtoClass_Iii}> xxxList = service.${methodName_iii}(act.getConnection(),
					displayStart, displayLength, argBean);
			//把结果放入出参中
			act.setArrayValue("jsonResult", xxxList.toArray());

<#elseif optType == "3">
			// 调用service方法
			service.${methodName_iii}(act.getConnection(), argBean);

</#if>

			return 1;

		} catch (SupException oe) {
			LOGGER.info("抓住了业务异常！！！"+oe.toString());
			act.setErrorContext(oe.getCode(), oe.getMsg(), oe);
			return 0;

		} catch (Exception e) {
			act.setErrorContext("${actionDesc}出错", "${actionDesc}出错", e);

			return 0;
		}
	}

}